'use strict';

import { get, post } from './HttpFetch';

class Controller {
  static getTemplate(id : number, item : String) {
    var json = null;
    var resolve = function(data){
      json = data;
    };
    var reject = function(errorMsg) { throw errorMsg; };
    var paras = { id : id, item : item };
    get(false, "/style/template", paras, resolve, reject, 10000);

    return json;
  }

  static updateTemplate(id : number, item : String, styleObject : {}) {
    var resolve = function(data){
      console.log('here');
    };
    var reject = function(errorMsg) { throw errorMsg; };
    var paras = { id : id, item : item };
    post(false, "/style/template", paras, JSON.stringify(styleObject), resolve, reject, 10000);
  }

  static getPage(enterpriseId : number, id : number, versionId : number) {
    var json = null;
    var resolve = function(data){
      json = data;
    };
    var reject = function(errorMsg) { throw errorMsg; };
    var paras = { enterpriseId : enterpriseId, id : id, versionId : versionId };
    get(false, "/style/page", paras, resolve, reject, 10000);

    return json;
  }

  static updatePage(enterpriseId : number, id : number, versionId : number, styleObject : {}) {
    var resolve = function(data){
      console.log('here');
    };
    var reject = function(errorMsg) { throw errorMsg; };
    var paras = { enterpriseId : enterpriseId, id : id, versionId : versionId };
    post(false, "/style/page", paras, JSON.stringify(styleObject), resolve, reject, 10000);
  }

  static getItem(enterpriseId : number, id : number, versionId : number) {
    var json = null;
    var resolve = function(data){
      json = data;
    };
    var reject = function(errorMsg) { throw errorMsg; };
    var paras = { enterpriseId : enterpriseId, id : id, versionId : versionId };
    get(false, "/style/item", paras, resolve, reject, 10000);

    return json;
  }

  static updateItem(enterpriseId : number, id : number, versionId : number, styleObject : {}) {
    var resolve = function(data){
      console.log('here');
    };
    var reject = function(errorMsg) { throw errorMsg; };
    var paras = { enterpriseId : enterpriseId, id : id, versionId : versionId };
    post(false, "/style/item", paras, JSON.stringify(styleObject), resolve, reject, 10000);
  }

  static getOperation(enterpriseId : number, id : number, versionId : number) {
    var json = null;
    var resolve = function(data){
      json = data;
    };
    var reject = function(errorMsg) { throw errorMsg; };
    var paras = { enterpriseId : enterpriseId, id : id, versionId : versionId };
    get(false, "/style/operation", paras, resolve, reject, 10000);

    return json;
  }

  static updateOperation(enterpriseId : number, id : number, versionId : number, styleObject : {}) {
    var resolve = function(data){
      console.log('here');
    };
    var reject = function(errorMsg) { throw errorMsg; };
    var paras = { enterpriseId : enterpriseId, id : id, versionId : versionId };
    post(false, "/style/operation", paras, JSON.stringify(styleObject), resolve, reject, 10000);
  }
};

module.exports=Controller;
